<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\StoreStyleService;

class StoreStyleController extends CommonController{
	private $storeStyleService;
    public function __construct(Request $request){
    	$this->storeStyleService = new StoreStyleService();
        parent::__construct($request); 
    }
    
    
    /**
     * 管理员列表
     */
    function index(){
    	$name = $this->request->input('name');
    	$start_time = $this->request->input('start_time');
    	$end_time   = $this->request->input('end_time');
    	$where = array();
    	if(isset($name) && $name !=''){
    		$where[] = array('name','like','%'.$name.'%');
    	}
    	
    	if(isset($start_time) && $start_time !=''){
    		$where[] = array('created_at','>=',$start_time);
    	}
    	
    	if(isset($end_time) && $end_time !=''){
    		$where[] = array('created_at','<=',$end_time);
    	}
    	
		$result = $this->storeStyleService->findAllInfo($where);
    	return view('store.style.index',['data'=>$result]);
    }
    
    /**
     * 添加
     */
    function add(){
    	
    	if($this->request->isMethod('post')){
    		$param = $this->request->except('_token');
    		$result = $this->storeStyleService->addInfo($param);
    		
    		return response()->json($result);
    	}else{
    		return view('store.style.add');
    	}
    	
    }
    
    
    /**
     * 编辑
     */
    function edit(){
    	$id = $this->request->input('id');
    	$where = [['id','=',$id]];
    	if($this->request->isMethod('post')){
    		$param = $this->request->except('id','_token');
    		$result = $this->storeStyleService->updateInfo($where,$param);

    		return response()->json($result);
    	}else{
    		$result = $this->storeStyleService->findInfo($where);
    		return view('store.style.edit',['info'=>$result['data']]);
    	}
    }
    
    /*
     * 删除
     */
    function delete(){
    	$id = $this->request->input('id');
    	$where = [['id','=',$id]];
    	$result = $this->storeStyleService->deleteInfo($where);
    	return response()->json($result);
    }
    
   
}
